home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / ObjEvent.au3 < prev    next >
Text File  |  2007-09-08  |  2KB  |  67 lines

  1. ; ObjEvent example
  2.  
  3. ProgressOn("Example", "Loading page...")
  4. $oIE=ObjCreate("InternetExplorer.Application.1")       ; Create Internet Explorer application
  5. $SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") ; Assign events to UDFs starting with IEEvent_
  6.  
  7. ; Do some browsing activities
  8. $oIE.Visible=1
  9. $oIE.RegisterAsDropTarget = 1
  10. $oIE.RegisterAsBrowser = 1
  11. $oIE.Navigate( "http://www.AutoItScript.com/" )
  12.  
  13. sleep(3000)            ; Give it time to load the web page
  14.  
  15. $SinkObject=0            ; Stop IE Events
  16. $oIE.Quit            ; Quit IE
  17. $oIE=0
  18. exit
  19.  
  20. ; one of many Internet Explorer Event Functions
  21.  
  22. Func IEEvent_ProgressChange($Progress,$ProgressMax)
  23.   $percent = Int( ($Progress * 100) / $ProgressMax )
  24.   If $percent >= 0 And $percent <= 100 Then
  25.     ProgressSet ( $percent , $percent & " percent to go." , "loading web page" )
  26.   EndIf
  27.  
  28. EndFunc
  29.  
  30. Exit
  31.  
  32. ; COM Error Handler example
  33. ; ------------------------- 
  34.  
  35. $oIE=ObjCreate("InternetExplorer.Application.1")    ; Create Internet Explorer application
  36. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
  37.  
  38. $oIE.UnknownMethod        ; Deliberately call an undefined method
  39.  
  40. If @error then
  41.   Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error)
  42. Else
  43.   Msgbox (0,"AutoItCOM test","Test failed!")
  44. Endif
  45.  
  46. Exit
  47.  
  48. ; This is my custom defined error handler
  49. Func MyErrFunc()
  50.  
  51.   Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
  52.              "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
  53.              "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
  54.              "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
  55.              "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
  56.              "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
  57.              "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
  58.              "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
  59.              "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
  60.             )
  61.             
  62.     Local $err = $oMyError.number
  63.     If $err = 0 Then $err = -1
  64.     
  65.     SetError($err)  ; to check for after this function returns
  66. Endfunc
  67.